package web;

import beans.LoginStatus;
import beans.User;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import Utils.JSONUtils;

import java.io.IOException;

@WebServlet(value = "/user/getUser")
public class getUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User existUser = (User) request.getSession().getAttribute("existUser");
        if (existUser != null) {
            response.getWriter().write(JSONUtils.result(LoginStatus.LOGIN_SUCCESS, existUser));
        }else {
            response.getWriter().write(JSONUtils.result(LoginStatus.LOGIN_OUT,null));
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
